import React, { useReducer } from "react";


const reducer = (state, action) => {
    if (action === '+') {
        return state + 1;
    }
    if (action === '-') {
        return state - 1;
    }
};

function Reducer(){
    // const [count, setCount] = useState(0);

    const [count, dispatch] = useReducer(reducer, 0);

    return(
        <div>
           Count: {count}
           <br />
           <button onClick={() => dispatch('+')}>+</button>
           <button onClick={() => dispatch('-')}>-</button>

           {/* <button onClick={() => setCount(count + 1)}>+</button>
           <button onClick={() => setCount(count - 1)}>-</button> */}
        </div>
    )
}

export default Reducer;